﻿// <copyright file="InformInit.cs" company="Hallvard Korsgaard">
//  Microsoft Public License (Ms-PL). See license details here: http://enoceannet.codeplex.com/license
// </copyright>
// <author>Hallvard Korsgaard</author> 

namespace EnOcean.Message
{
  using System;
  using System.Text;

  /// <summary>
  /// After a power-on, a hardware reset or a RESET command the TCM 120 module informs the user through several of these telegrams about the current status. 
  /// </summary>
  [Serializable]
  public class InformInit : MessageTelegram
  {
    /// <summary>
    /// Variable for the Text property.
    /// </summary>
    private string text;

    /// <summary>
    /// Gets the modem status text.
    /// </summary>
    public string Text
    {
      get
      {
        return this.text;
      }

      internal set
      {
        if (!string.IsNullOrEmpty(value))
        {
          if (value.Length <= 9)
          {
            this.text = value;
          }
          else
          {
            throw new ArgumentOutOfRangeException("Text", "Must be 9 characters or less.");
          }
        }
        else
        {
          throw new ArgumentNullException("Text");
        }
      }
    }

    /// <summary>
    /// Creates the byte format of the message.
    /// </summary>
    /// <param name="message">A byte array of length 14 to hold the message contents.</param>
    protected internal override void CreateMessage(byte[] message)
    {
      base.CreateMessage(message);
      message[3] = (byte)MessageType.InformInit;
      Encoding.ASCII.GetBytes(this.text, 0, this.Text.Length, message, 4);
    }
  }
}
